//
//  WaitDealViewController.m
//  Mahjong
//
//  Created by mc on 16/9/9.
//  Copyright © 2016年 Elliot. All rights reserved.
//

#import "WaitDealViewController.h"
#import "Header.h"
#import "waitDetaModel.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
@interface WaitDealViewController ()
{
    NSString *addressString;
    UILabel *nameLable;
    UILabel *contentLable;
    UILabel *numberlable;
    UILabel *datalable;

    UIImageView *headimgView;
    
    UIImageView *oneImageView;
    UIImageView *twoImageVIew;
    UIImageView *threeImageView;
    
    
}




@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation WaitDealViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.backgroundColor = [UIColor colorWithWhite:0.900 alpha:1.000];
    
    addressString = [NSString stringWithFormat:@"穹翊 18243944222 收货地址: 浙江省杭州市围垦区震泽办公大厦C座3201"];
    self.dataArray = [NSMutableArray array];
//    [self addNav];
    [self addDetailUI];
    [self addImgViewUI];
    [self addAddressUI];
    [self addDingdanUI];
    [self addTwoButtonUI];
    self.navigationItem.title = @"订单详情";
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_but_back"] style:(UIBarButtonItemStyleDone) target:self action:@selector(backAction)];
    backItem.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = backItem;
    [self create];
}
-(void)create{
    [AppTools createAFN:[NSString stringWithFormat:@"http://api03.m0571.com/WebJson.aspx?book=GetRepairSingle&repairid=%ld",self.num] success:^(id result) {
        NSLog(@"%@",result);
        waitDetaModel *model = [[waitDetaModel alloc] init];
        for (NSDictionary *dic in [result[0] objectForKey:@"date"]) {
            [model setValuesForKeysWithDictionary:dic];
//            [self.dataArray addObject: model];
        }
        nameLable.text = model.name;
        contentLable.text = model.contents;
        numberlable.text = model.OrderId;
        datalable.text = model.addtime;
        [headimgView sd_setImageWithURL:[NSURL URLWithString:[model.photourl stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
        if (model.imagelist.count == 1) {
            [oneImageView sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[0] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            twoImageVIew.alpha = 0;
            threeImageView.alpha = 0;
        }
        if (model.imagelist.count == 2) {
            [oneImageView sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[0] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            [twoImageVIew sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[1] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            threeImageView.alpha = 0;
        }
        if (model.imagelist.count == 3) {
            //        NSString *s = [model.imagelist[0] objectForKey:@"imageurl"];
            //        NSString *newImgStr =  [[model.imagelist[0] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com"];
            [oneImageView sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[0] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            [twoImageVIew sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[1] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            [threeImageView sd_setImageWithURL:[NSURL URLWithString:[[model.imagelist[2] objectForKey:@"imageurl"] stringByReplacingOccurrencesOfString:@"~" withString:@"http://api03.m0571.com" ]]];
            
        }

    } error:^(NSError *error) {
        
        
    }];
}
- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

// 处理导航栏
//- (UIStatusBarStyle)preferredStatusBarStyle
//{
//    return UIStatusBarStyleLightContent;
//}
-(void)addNav{
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, WIDTH, 40)];
    _backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_backView];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"nav_but_back"] forState:UIControlStateNormal];
    backBtn.backgroundColor = [UIColor clearColor];
    backBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(20, 5, 25, 25);
    [_backView addSubview:backBtn];
    
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 2 / 5 - 8, 0, WIDTH / 5, 40)];
    lable.backgroundColor = [UIColor whiteColor];
    lable.text = @"发布详情";
    lable.font = [UIFont systemFontOfSize:20];
    lable.textAlignment = NSTextAlignmentCenter;
    [self.backView addSubview:lable];
    
}
-(void)backBtnAction{
    [self.navigationController popViewControllerAnimated:YES];
}
// 发布人信息
-(void)addDetailUI{
    UIView *statesView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_backView.frame)+10, WIDTH, HEIGHT/12 + 20)];
    statesView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:statesView];
    
    headimgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, HEIGHT/12, HEIGHT/12)];
    headimgView.backgroundColor = [UIColor grayColor];
    headimgView.image = [UIImage imageNamed:@""];
    headimgView.layer.cornerRadius = headimgView.frame.size.height/2;
    [statesView addSubview:headimgView];
    
    nameLable = [[UILabel alloc] initWithFrame:CGRectMake(HEIGHT/12 + 20,  10, WIDTH / 3, HEIGHT/24)];
    //    nameLable.backgroundColor = [UIColor redColor];
    nameLable.text = @"穹翊 2016-06-07";
    //    nameLable.textAlignment = NSTextAlignmentCenter;
    [statesView addSubview:nameLable];
    
    contentLable = [[UILabel alloc] initWithFrame:CGRectMake(HEIGHT/12 + 20, HEIGHT/24 + 10, WIDTH/2, HEIGHT/24)];
    //    contentLable.backgroundColor = [UIColor redColor];
    contentLable.text = @"麻将机卡坏了, 不能洗牌了";
    contentLable.textColor = [UIColor grayColor];
    [statesView addSubview:contentLable];
}
// 图片信息
-(void)addImgViewUI{
    UIView *statesView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_backView.frame) + HEIGHT/12 + 40, WIDTH, HEIGHT/6.5)];
    statesView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:statesView];
    
    oneImageView = [[UIImageView alloc] initWithFrame:CGRectMake((10+HEIGHT/6.5 - 20)*0 + 15, 10, HEIGHT/6.5-20, HEIGHT/6.5-20)];
    oneImageView.backgroundColor = [UIColor grayColor];
    oneImageView.image = [UIImage imageNamed:@""];
    [statesView addSubview:oneImageView];
    
    twoImageVIew = [[UIImageView alloc] initWithFrame:CGRectMake((10+HEIGHT/6.5 - 20)*1 + 15, 10, HEIGHT/6.5-20, HEIGHT/6.5-20)];
    twoImageVIew.backgroundColor = [UIColor grayColor];
    twoImageVIew.image = [UIImage imageNamed:@""];
    [statesView addSubview:twoImageVIew];
    
    threeImageView = [[UIImageView alloc] initWithFrame:CGRectMake((10+HEIGHT/6.5 - 20)*2 + 15, 10, HEIGHT/6.5-20, HEIGHT/6.5-20)];
    threeImageView.backgroundColor = [UIColor grayColor];
    threeImageView.image = [UIImage imageNamed:@""];
    [statesView addSubview:threeImageView];
    
//    for (NSInteger i = 0; i < 3; i++) {
//        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((10+HEIGHT/6.5 - 20)*i + 15, 10, HEIGHT/6.5-20, HEIGHT/6.5-20)];
//        imgView.backgroundColor = [UIColor grayColor];
//        imgView.image = [UIImage imageNamed:@""];
//        [statesView addSubview:imgView];
//    }
}
// 地址信息
-(void)addAddressUI{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_backView.frame) + HEIGHT/12 + 40 + HEIGHT/6.5 + 10, WIDTH, HEIGHT / 11)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 5, HEIGHT/22, HEIGHT/22);
//    [btn addTarget:self action:@selector(sendAddressAction) forControlEvents:UIControlEventTouchUpInside];
    //    btn.backgroundColor = [UIColor redColor];
    [btn setImage:[UIImage imageNamed:@"else_icon_map"] forState:UIControlStateNormal];
    [backView addSubview:btn];
    
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(HEIGHT/22, 0, WIDTH - HEIGHT /11, HEIGHT/11)];
    //    lable.backgroundColor = [UIColor redColor];
    lable.text = addressString;
    lable.textColor = [UIColor grayColor];
    lable.numberOfLines = 0;
    [backView addSubview:lable];
    
}
// 订单号
-(void)addDingdanUI{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_backView.frame) + HEIGHT/12 + 58 + HEIGHT/6.5  + HEIGHT / 11, WIDTH, HEIGHT / 11)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    numberlable = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, WIDTH/2, HEIGHT/22 -5)];
//    numberlable.backgroundColor = [UIColor redColor];
    numberlable.text = @"订单号: 6595425845";
    numberlable.textColor = [UIColor grayColor];
    [backView addSubview:numberlable];
    
    datalable
    = [[UILabel alloc] initWithFrame:CGRectMake(10, 5 + HEIGHT/22, WIDTH/2, HEIGHT/22 -5)];
//    dataLable.backgroundColor = [UIColor redColor];
    datalable.text = @"2016-06-07-14:00";
    datalable.textColor = [UIColor grayColor];
    [backView addSubview:datalable];
    
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 100, 10, 90, HEIGHT/11-20)];
//    lable.backgroundColor = [UIColor redColor];
    lable.text = @"未受理";
    lable.textColor = [UIColor grayColor];
    [backView addSubview:lable];
}
// 取消订单 催单
-(void)addTwoButtonUI{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 110, WIDTH, 50)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    UIButton *cuiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cuiBtn.frame = CGRectMake(WIDTH - 15 - WIDTH/5, 5, WIDTH/5, 40);
    [cuiBtn addTarget:self action:@selector(cuidanAction) forControlEvents:UIControlEventTouchUpInside];
    cuiBtn.backgroundColor = [UIColor colorWithRed:255/255.0 green:61/255.0 blue:87/255.0 alpha:1.000];
    [cuiBtn setTitle:@"催单" forState:UIControlStateNormal];
    [cuiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    cuiBtn.layer.cornerRadius = 5;
    [backView addSubview:cuiBtn];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(WIDTH - 25 - WIDTH /5 - WIDTH/4, 5, WIDTH/4, 40);
    [btn addTarget:self action:@selector(cuidanAction) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:178/255.0 blue:115/255.0 alpha:1.000];
    [btn setTitle:@"取消订单" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    [backView addSubview:btn];
    
}
-(void)cuidanAction{
    
}


//-(void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:YES];
//    self.navigationController.navigationBarHidden = YES;
//    self.tabBarController.tabBar.hidden = YES;
//}
//-(void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:YES];
//    self.navigationController.navigationBarHidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
